package wiki;

import java.io.IOException;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Root;

/**
 * Servlet implementation class SaveFeedback
 */
public class publishIssue extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public publishIssue() {
        super();
        // TODO Auto-generated constructor stub
        
        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		Root root = new Root();
		String sql = "";
		PreparedStatement pst=null;
		
		String user="";
		user = request.getParameter("user");
		
	try{
		
		
		
		String ids = request.getParameter("ids");
		
		if ((ids != null) || (!ids.equals(""))) {

			
			root.initConnection();
			sql = "update issue set published=1 , publishedby = ? where id in (" + ids +")";

			
			pst = root.con.prepareStatement(sql);
			pst.setString(1, user);
			//pst.setString(1, ids);
						
			//System.out.println("SQL: " + pst);
			pst.executeUpdate();
		
		}
		
	}catch(Exception e){
		
		System.out.println("Error publishing");
	}finally{
		try {
			pst.close();
			root.closeConnection();
		} catch (Exception e) {
			
		}
	}
	
	
	}

}
